
#include <iostream>
#include <gtest/gtest.h>
#include <unordered_map>

//全局测试套件，独立测试套件

//独立测试套件，可以自己定义成员变量，成员变量可以是独立的，是与当前测试套件相关的
//单元测试才能访问的, 继承于 testing::Test

class MyEnvironment:public testing::Environment
{
public:
    virtual void SetUp() override
    {
        std::cout << "单元测试前执行的环境初始化操作" << std::endl;
    }

    virtual void TearDown() override
    {
        std::cout << "单元测试执行完毕后的环境清理" << std::endl;
    }
};

TEST(MyEnvironment, test1)
{
    std::cout << "单元测试1" << std::endl;
}


TEST(MyEnvironment, test2)
{
    std::cout << "单元测试2" << std::endl;
}

std::unordered_map<std::string, std::string> mymap;
class MyMapTest : public testing::Environment {
    public:
        virtual void SetUp() override {
            std::cout << "单元测试执行前的环境初始化！！\n";
            mymap.insert(std::make_pair("hello", "你好"));
            mymap.insert(std::make_pair("bye", "再见"));
        }
        virtual void TearDown() override {
            std::cout << "单元测试执行完毕后的环境清理！！\n";
            mymap.clear();
        }
};

TEST(MyMapTest, test1) {
    ASSERT_EQ(mymap.size(), 2);
    //mymap.erase("hello");
}

TEST(MyMapTest, test2) {
    ASSERT_EQ(mymap.size(), 2);
}


int main(int argc, char* argv[])
{
    testing::InitGoogleTest(&argc, argv);
    testing::AddGlobalTestEnvironment(new MyEnvironment);
    testing::AddGlobalTestEnvironment(new MyMapTest);

    return RUN_ALL_TESTS();
}
